package com.atguigu.realtime.gmallpublisher.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/3/27 14:02
 */
public interface KeyWordStatsMapper {
    
    @Select("select " +
        "        keyword,\n" +
        "        sum(ct * multiIf(\n" +
        "                    source = 'SEARCH', 10,\n" +
        "                    source = 'ORDER', 5,\n" +
        "                    source = 'CART', 2,\n" +
        "                    source = 'CLICK', 1,\n" +
        "                    0)) ct\n" +
        " from keyword_stats_2021\n" +
        " where toYYYYMMDD(stt)=#{date}\n" +
        " group by keyword\n" +
        " order by ct desc\n" +
        " limit #{limit}")
    List<Map<String, Object>> getKeyWordStats(@Param("date") int date,
                                              @Param("limit") int limit);
}
